<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<head th:include="/base/common_css('test')">
<body>
<div th:include="/base/common_banner"></div>
<!-- Main content starts -->

<div class="content">
    <!-- Sidebar -->
    <div th:include="/base/common_menu"></div>
    <!-- Sidebar
    <div class="sidebar">
        <div class="sidebar-dropdown"><a href="#">Navigation</a></div>

    </div>-->
    <!-- Matter -->
    <div class="mainbar">
        <!-- Page heading -->
        <div th:include="/base/common_pageHeader"></div>

        <div class="matter">
            <div class="container">
                <div class="row">
                    <div class="col-md-6">


                        <div class="widget wgreen">

                            <div class="widget-head">
                                <div class="pull-left">支付类型详情</div>
                                <div class="widget-icons pull-right">
                                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                                </div>
                                <div class="clearfix"></div>
                            </div>

                            <div class="widget-content">
                                <div class="padd">

                                    <!-- Form starts.  -->
                                    <form class="form-horizontal" role="form" action="#" method="post">

                                        <div class="modal-body">
                                            <form action="#" method="post"
                                                  enctype="multipart/form-data">
                                                <input class="col-lg-4 form-control " type="hidden" id="rechId"
                                                       th:value="${rechId}">
                                                <div class="form-group">
                                                    <label class="col-lg-4 control-label">支付金额</label>
                                                    <div class="col-lg-4">
                                                        <input type="text" th:value="${money}" class="form-control"
                                                               id="money" placeholder="支付金额"
                                                        >
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="col-lg-4 control-label">支付类型</label>
                                                    <div class="col-lg-4">
                                                        <select id="rechType" class="form-control"
                                                                onchange="selectOnchang(this)">
                                                            <!--<option>&#45;&#45;&#45;&#45;请选择类型&#45;&#45;&#45;&#45;</option>-->
                                                            <!--<option value="0">积分充值</option>-->
                                                            <!--<option value="1">会员充值</option>-->
                                                            <option th:each="recharges:${rechTypeList}"
                                                                    th:value="${recharges.key}"
                                                                    th:text="${recharges.value}"
                                                                    th:selected="${recharges.key == rechType}"></option>
                                                        </select>
                                                    </div>
                                                </div>

                                                <div class="form-group" style='display:none;' id="div1">
                                                    <label class="col-lg-4 control-label">积分</label>
                                                    <div class="col-lg-4">
                                                        <input type="text" th:value="${point}" class="form-control"
                                                               id="point" placeholder="积分"
                                                        >
                                                    </div>
                                                </div>
                                                <div class="form-group" style='display:none;' id="div2">
                                                    <label class="col-lg-4 control-label">有效期</label>
                                                    <div class="col-lg-4">
                                                        <select id="timeLimit"
                                                                class="selectpicker show-tick form-control"
                                                                data-live-search="false">
                                                            <option th:each="times:${timesList}"
                                                                    th:value="${times.key}" th:text="${times.value}"
                                                                    th:selected="${times.key == timeLimit}"></option>

                                                        </select>
                                                    </div>
                                                </div>

                                                <div class="form-group" style='display:none;' id="div3">
                                                    <label class="col-lg-4 control-label">有效次数</label>
                                                    <div class="col-lg-4">
                                                        <input type="text" th:value="${frequency}" class="form-control"
                                                               id="frequency" placeholder="有效次数">
                                                    </div>
                                                </div>
                                                <div class="form-group" style='display:none;' id="div">
                                                    <label class="col-lg-4 control-label">序号</label>
                                                    <div class="col-lg-4">
                                                        <input type="text" th:value="${sort}" class="form-control"
                                                               id="sort" placeholder="序号">
                                                    </div>
                                                </div>


                                            </form>

                                        </div>
                                    </form>
                                    <div class="modal-footer">
                                        <button type="button" onclick="saveRecharge()"
                                                class="btn btn-success">保存
                                        </button>
                                        <button type="button" class="btn btn-cancel"
                                                onclick="canceles()">取消
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- Mainbar ends -->
<div class="clearfix"></div>

</div>
<!-- Content ends -->

<div th:include="/base/common_footer"></div>
<!-- Scroll to top -->
<span class="totop"><a href="#"><i class="icon-chevron-up"></i></a></span>
<!--js????-->
<div th:include="/base/common_js"></div>
<script type="text/javascript">

    function canceles() {
        window.location = "/view/rechargeList?pageNumber=1&pageSize=10";
    }

    //保存新增/修改
    function saveRecharge() {

        if ($('#rechType').val().trim().length == 0) {
            alert("支付类型不能为空");
        } else {
            if ($('#money').val().trim().length == 0) {
                alert("所需金额不能为空");
            } else {
                if (/^(0|[1-9][0-9]*)$/.test($("#money").val())) {
                    var data = {
                        'rechId': $('#rechId').val(),
                        'money': $('#money').val(),
                        'rechType': $('#rechType').val(),
                        'point': $('#point').val() == undefined || $('#point').val() == '' ? 0 : $('#point').val(),
                        'timeLimit': $('#timeLimit').val(),
                        'frequency': $('#frequency').val() === undefined || $('#frequency').val() === '' ? 0 : $('#frequency').val(),
                        'sort': $('#sort').val()
                    }
                    $.ajax({
                        url: "/view/saveOrUpdateRecharge",
                        type: "POST",
                        dataType: "json",
                        data: data,
                        success: function (data) {
                            if (data.data) {
                                window.location.href = "/view/rechargeList?pageNumber=1&pageSize=10";
                            }
                        },
                    });
                } else {
                    alert("金额格式错误！！");
                }

            }

        }
    }
    function selectOnchang(obj) {
//        var value = obj.options[obj.selectedIndex].value;
//        alert(value);
        if (obj.options[obj.selectedIndex].value == 0) {
            $('#div1').show();
            $('#div').show();
            $('#div2').hide();
            $('#div3').hide();
        } else if (obj.options[obj.selectedIndex].value == 1) {
            $('#div2').show();
            $('#div3').show();
            $('#div').show();
            $('#div1').hide();
        } else {
            window.location = "/view/saveRecharge";
        }

    }


</script>

</body>
</html>